package com.cz.nongyetongv5.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CharsetUtil {

	/**
	 * 判断字符串不为空
	 *
	 * @param str
	 * @return 不为空的时候返回true
	 */
	public static boolean isNotNull(String str) {

		if (str != null) {
			str = str.trim();
		} else {
			return false;
		}

		if (str != null && !"".equals(str) && !"null".equalsIgnoreCase(str)) {
			return true;
		} else {
			return false;
		}

	}

	/**
	 * 检验号码
	 *
	 * @return
	 */
	public static boolean checkPhone(String phone) {

		String reg = "^(((\\(\\d{3}\\))|(\\d{3}\\-))?(\\(0\\d{2,3}\\)|0\\d{2,3}-)?[1-9]\\d{6,7}|((\\+86)|(86)|(0))?((13)|(15)|(18))\\d{9})$";



		return match(reg, phone);


	}


	/**
	 * 检测样品编号前两位
	 * @return
	 */
	public static boolean checkYangPinBianHaoLiangWei(String str){

		String reg = "^\\d{2}$";

		return match(reg, str) ;

	}


	/**
	 * 检测编号的后一位
	 * @param str
	 * @return
	 */
	public static boolean checkYangPinBianHaoYiWei(String str){

		String reg = "^\\d{1}$";

		return match(reg, str) ;

	}


	private static boolean match(String regex, String str) {
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(str);
		return matcher.matches();
	}

}
